from rest_framework.permissions import DjangoModelPermissions, IsAdminUser

from apps.goods.models import SPU,Brand,GoodsCategory
from rest_framework.viewsets import ModelViewSet
from apps.wthg_admin.utils import UtilsPageNumberPagination
from apps.wthg_admin.serializers.spu import SPUModelSerializer,BrandModelSerializer,GoodsCategoryModelSerializer
from rest_framework.generics import ListAPIView

class SPUModelViewSet(ModelViewSet):
    """SPU管理视图"""
    queryset = SPU.objects.all()
    serializer_class = SPUModelSerializer
    pagination_class = UtilsPageNumberPagination


class BrandListAPIView(ListAPIView):
    """获取品牌名称视图"""
    queryset = Brand.objects.all()
    serializer_class = BrandModelSerializer


class GoodsCategory_1ListAPIView(ListAPIView):
    """获得一级分类视图"""
    queryset = GoodsCategory.objects.filter(parent=None)
    serializer_class = GoodsCategoryModelSerializer


class GoodsCategory_2_3ListAPIView(ListAPIView):
    """获得二，三级分类视图"""

    def get_queryset(self):
        return GoodsCategory.objects.filter(parent_id=self.kwargs.get('pk'))
    serializer_class = GoodsCategoryModelSerializer

